from typing import List


class Solution:

    # 让前 k + 1 个数的差值分别为 k, k - 1, k - 1,……1。
    # 前k + 1个数为：1, k + 1, 2, k, 3, k - 1, 4, k - 2, 5,……
    #
    # 剩下的数从 k + 2 依次赋值，因为从 k + 2 开始的数还没有使用，而且二者之差也被前面的差值包含了。

    def constructArray(self, n: int, k: int) -> List[int]:
        res = [1] * n
        diff = k
        for i in range(1, k + 1):
            res[i] = res[i - 1] + diff if i % 2 else res[i - 1] - diff
            diff -= 1

        for i in range(k + 1, n):
            res[i] = i + 1
        return res